﻿@using RH.Web.Utility;
@{
    String pageTitle = "Search Configuration";
    ViewBag.Title = "Re Index Properties";
    RH.Search.ReIndexResult _Result = ViewData[AppConstants.ViewDataKeys.SAVED] as RH.Search.ReIndexResult; 
}
<div class="rh-page-heading">
    <h1>@pageTitle</h1>
    <div>
        Manage and Configure Product and Category Searching
    </div>
</div>


<div class="rh-page-content">
    
    @*<div>Deleted Index from DB: @_Result.DeletedIndexFromDB</div>
    <div>Deleted Index from Lucene: @_Result.DeletedIndexFromLucene</div>
    <div>Found Products for Re-Index: @_Result.FoundItems</div>
    <div>Successfully Indexed: @_Result.ReIndexedItems</div>*@
    <div id="divResult"></div>    
    <button type="button" class="btn btn-primary" onclick="ReIndexProducts();"><i class="glyphicon glyphicon-refresh"></i> Re Index Properties</button>
</div>

@section JavaScriptPlaceholder{
    <script language="javascript" type="text/javascript">
        function ReIndexProducts() {
            var div = $('#divResult').html('');
            ShowLoadingAnimation(true);
            Ajax('@Url.AdminUrl("ReIndexProducts", "SearchConfig")', null, function (result) {
                HideLoadingAnimation();
                var jobStatus = eval('(' + result + ')');
                BindResult(jobStatus, 'Properties', div);
            });
        }
        
        function BindResult(reIndexResult, title, container) {
            var html = '';
            if (typeof (reIndexResult.Error) === 'undefined' || reIndexResult.Error.length == 0) {
                html = '<div>Deleted Index from DB: ' + reIndexResult.DeletedIndexFromDB + '</div>' +
                        '<div>Deleted Index from Lucene: ' + reIndexResult.DeletedIndexFromLucene + '</div>' +
                        '<div>Found ' + title + ' for Re-Index: ' + reIndexResult.FoundItems + '</div>' +
                        '<div>Successfully Indexed: ' + reIndexResult.ReIndexedItems + '</div>';
                html = SuccessMessageBox(html, '');
            }
            else
                html = WarningMessageBox(reIndexResult.Error, 'Error! Following Error Occured In Server.');
            $(container).html(html).show();
        }
    </script>
}
